package com.rtu.dto.response;

import com.rtu.enums.Code;

/**
 * Created by lzm on 17/5/14.
 */
public class ApiResponse {
    private boolean success;
    private String message;
    private int code;
    private Object data;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static ApiResponse create(boolean success, String message,int code, Object data){
        ApiResponse apiResponse = new ApiResponse();
        apiResponse.setCode(code);
        apiResponse.setMessage(message);
        apiResponse.setData(data);
        apiResponse.setSuccess(success);
        return apiResponse;
    }

    public static ApiResponse create(boolean success, Code code, Object data){
        ApiResponse apiResponse = new ApiResponse();
        apiResponse.setCode(code.code);
        apiResponse.setMessage(code.msg);
        apiResponse.setData(data);
        apiResponse.setSuccess(success);
        return apiResponse;
    }

    public static ApiResponse createUserNotLogin(){
        ApiResponse apiResponse = new ApiResponse();
        apiResponse.setCode(Code.USER_NOT_LOGIN.code);
        apiResponse.setMessage(Code.USER_NOT_LOGIN.msg);
        apiResponse.setData(new Object());
        apiResponse.setSuccess(false);
        return apiResponse;
    }

    public static ApiResponse createUserNoAuth(){
        ApiResponse apiResponse = new ApiResponse();
        apiResponse.setCode(Code.USER_NO_AUTH.code);
        apiResponse.setMessage(Code.USER_NO_AUTH.msg);
        apiResponse.setData(new Object());
        apiResponse.setSuccess(false);
        return apiResponse;
    }
}
